//AS3///////////////////////////////////////////////////////////////////////////
// 
// Copyright 2010 
// 
////////////////////////////////////////////////////////////////////////////////

package
{

	import flash.events.Event;
	import flash.display.Sprite;
	import org.papervision3d.view.BasicView;
	import org.mistlab.RAIDemo;
	import org.papervision3d.core.proto.CameraObject3D;
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.materials.special.LineMaterial;
	import com.greensock.TweenLite;
	import com.greensock.easing.Quint;
	import flash.events.MouseEvent;
	import com.greensock.TweenMax;
	import com.greensock.TimelineLite;
	import com.greensock.TimelineMax;
	import YogaPlusLife_Lotus;
	import org.mistlab.YogaPlusLife_Lotus;

	/**
	 * Application entry point for Model.
	 * 
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 9.0
	 * 
	 * @author alex
	 * @since 04.03.2010
	 */
	[SWF(width="640", height="480", backgroundColor="0x000000", frameRate="30")]
	public class Model extends BasicView
	{
	    
	    private var _axes:Lines3D = new Lines3D();	    
        private var timeline:TimelineMax = new TimelineMax();        
        /*private var demoObject:RAIDemo = new RAIDemo();*/
        private var demoObject:YogaPlusLife_Lotus = new YogaPlusLife_Lotus();
	
		/**
		 * @constructor
		 */
		public function Model()
		{
			super();
			stage.addEventListener( Event.ENTER_FRAME, initialize );
		}

		/**
		 * Initialize stub.
		 */
		private function initialize(event:Event):void
		{
			stage.removeEventListener( Event.ENTER_FRAME, initialize );
						
            /*camera.x = 0;
            camera.y = 0;
            camera.z = -2000;*/
            
            camera.x = 1;
            camera.y = 2000;
            camera.z = 1;
            
            
			
			scene.addChild(demoObject);
			
			initAxes();
			initButtons();		
            
            startRendering();         
		}
		
		public function initAxes():void
		{
		    scene.addChild(_axes);
			_axes.addLine(new Line3D(_axes, new LineMaterial(0x0000ff), 3, new Vertex3D(-1000, 0, 0), new Vertex3D(2000, 0, 0)));
			_axes.addLine(new Line3D(_axes, new LineMaterial(0x00ff00), 3, new Vertex3D(0, -1000, 0), new Vertex3D(0, 2000, 0)));
			_axes.addLine(new Line3D(_axes, new LineMaterial(0xff0000), 3, new Vertex3D(0, 0, -1000), new Vertex3D(0, 0, 2000)));
		}
		
		public function initButtons():void
		{
		    var b1:Sprite = createButton(0xff0000);
		    var b2:Sprite = createButton(0x00ff00);
		    var b3:Sprite = createButton(0x0000ff);
		    b2.x = b1.x + 20;
		    b3.x = b2.x + 20;
		    
		    addChild(b1);
		    addChild(b2);
		    addChild(b3);
		    
		    b1.addEventListener(MouseEvent.CLICK, redAction);
		    b2.addEventListener(MouseEvent.CLICK, greenAction);
		    b3.addEventListener(MouseEvent.CLICK, blueAction);
		    
		}
		
		
		public function createButton(color:uint):Sprite
    	{
    	    var btn:Sprite = new Sprite();
    	    
    	    btn.graphics.beginFill(color);
    	    btn.graphics.moveTo(0, 0);
    	    btn.graphics.lineTo(0, 20);
    	    btn.graphics.lineTo(20, 20);
    	    btn.graphics.lineTo(20, 0);
    	    btn.graphics.lineTo(0, 0);
    	    btn.graphics.endFill();
    	    
    	    btn.buttonMode = true;
    	    
    	    return btn;
    	}
    	
    	public function redAction(e:MouseEvent):void
    	{
           /**/
           var tl:TimelineMax = new TimelineMax({paused:true});
           /*tl.append(new TweenMax(camera, 2, {z:0, x:-500, ease:Quint.easeOut}));
           tl.append(new TweenMax(camera, 2, {z:2000, x:0, ease:Quint.easeOut}));
           tl.append(new TweenMax(camera, 2, {y:2000, ease:Quint.easeOut}));
           tl.append(new TweenMax(camera, 2, {z:0, x:500, ease:Quint.easeOut}));
           tl.append(new TweenMax(camera, 2, {z:-2000, x:500, ease:Quint.easeOut}));*/
           tl.append(new TweenMax(camera, 2, {y:2000, x:10, z:10, ease:Quint.easeOut}));
           tl.play();           
    	}
    	
    	public function greenAction(e:MouseEvent):void
    	{
    	    demoObject.building.show();
    	}
    	
    	public function blueAction(e:MouseEvent):void
    	{
    	    demoObject.building.hide();
    	}
    	
        /*override protected function onRenderTick(event:Event = null):void
        {
            super.onRenderTick(event);
            
        }*/
        
    	
	
	}

}